home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard CTB Toolkit 1.0b2 / Source Code / CTBSwitch.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  2.2 KB  |  88 lines  |  [TEXT/MPS ]

  1. (*
  2.     CTBSwitch([newToolID[,type]]) -- Return the ID of the current tool of the type specified (default:
  3.         connection). If newToolID is present, then switch to that tool; if it is "new", then prepare to
  4.         allocate a new tool.
  5.  
  6.     To compile and link this file using Macintosh Programmer's Workshop,
  7.  
  8.         pascal -w CTBSwitch.p
  9.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=2757 -sn Main=CTBSwitch ∂
  10.             CTBSwitch.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  11.  
  12.     © Copyright 1990 by Apple Computer, Inc.
  13.  
  14.     Initial coding 2/90 by Harry R. Chesley.
  15. *)
  16.  
  17. {$R-}
  18.  
  19. {$S CTBSwitch }     { Segment name must be the same as the command name. }
  20.  
  21. unit DummyUnit;
  22.  
  23. interface
  24.  
  25. uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
  26.  
  27. procedure EntryPoint(paramPtr: XCmdPtr);
  28.     
  29. implementation
  30.  
  31. procedure CTBSwitch(paramPtr: XCmdPtr); forward;
  32.  
  33. procedure EntryPoint(paramPtr: XCmdPtr);
  34.  
  35.     begin
  36.         CTBSwitch(paramPtr);
  37.     end;
  38.  
  39. procedure CTBSwitch(paramPtr: XCmdPtr);
  40.  
  41.     {$I CTBUtil.inc}
  42.  
  43.     var tt: ToolType;
  44.         toolID: longInt;
  45.         s: Str255;
  46.  
  47.     procedure Fail(errMsg: Str255); { set theResult and quit }
  48.         begin
  49.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  50.             exit(CTBSwitch);
  51.         end;
  52.  
  53.     begin
  54.         { Check the parameter count. }
  55.         if paramPtr^.paramCount > 2 then Fail('Invalid parameter count');
  56.  
  57.         { Figure out which type of tool. }
  58.         if not ParmPresent(2) then tt := connectionTool
  59.         else tt := GetToolTypeParm(2);
  60.  
  61.         { Make sure the Comm Toolbox is around. }
  62.         CTBReady;
  63.  
  64.         { Get the current tool handle (which we'll return as the ID). }
  65.         case tt of
  66.             connectionTool: toolID := ord4(Globals^^.connHand);
  67.             terminalTool: toolID := ord4(Globals^^.termHand);
  68.             fileTransferTool: toolID := ord4(Globals^^.FTHand);
  69.             end;
  70.         { Convert it to a string and return it. }
  71.         LongToStr(paramPtr,toolID,s);
  72.         paramPtr^.returnValue := PasToZero(paramPtr,s);
  73.  
  74.         { Check if we're to set a new one. }
  75.         if ParmPresent(1) then
  76.             begin
  77.                 { Set it (note: "new" will translate to 0). }
  78.                 toolID := GetLongParm(1);
  79.                 case tt of
  80.                     connectionTool: Globals^^.connHand := ConnHandle(toolID);
  81.                     terminalTool: Globals^^.termHand := TermHandle(toolID);
  82.                     fileTransferTool: Globals^^.FTHand := FTHandle(toolID);
  83.                     end;
  84.             end;
  85.     end;
  86.  
  87. end.
  88.